﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Game
    {
        internal bool Gaming(Hero hero, User user)
        {
            int sum = 0, hNum = 0, uNum = 0;
            while (true)
            {
                string heroAction = hero.Action();
                string userAction = user.Action();
                Console.WriteLine($"{hero.Name}：出拳：{heroAction}");
                Console.WriteLine($"{user.Name}：出拳：{userAction}");
                sum++;
                IsWin(heroAction, userAction, user.Name, ref hNum, ref uNum);
                Console.WriteLine("是否开始下一轮？（1.继续/0.停止）");
                string chioce = Console.ReadLine();
                if (chioce=="0")
                {
                    return EndGame(hero.Name,user.Name,sum,hNum,uNum);
                    
                    
                }
                else if (chioce=="1")
                {
                    continue;
                }
                
            }
           
        }

        private bool EndGame(string name1, string name2, int sum, int hNum, int uNum)
        {
            Console.WriteLine("=======================================");
            Console.WriteLine($"{name1} VS {name2}");

            Console.WriteLine($"对战次数: {sum}");

            Console.WriteLine("姓名\t得分");
            Console.WriteLine($"{name1}\t{hNum}");
            Console.WriteLine($"{name2}\t{uNum}");
            if (hNum > uNum)
            {
                Console.WriteLine($"{name1}赢了，{name2}输了");
            }
            else if (hNum < uNum)
            {
                Console.WriteLine($"{name2}赢了，{name1}输了");
            }
            else {
                Console.WriteLine("平局");
            }

            Console.WriteLine("要开始下一局吗？（y/n）");
            string chioce = Console.ReadLine();
            if (chioce == "y")
            {

                return true;
            }
            else if (chioce == "n")
            {
                return false;
                
            }
            return true;
        }

        private void IsWin(string A, string B, string name, ref int hNum, ref int uNum)
        {
            string temp;
            if (A == "布" && B == "石头" || A == "剪刀" && B == "布" || A == "石头" && B == "剪刀")
            {
                temp = "赢";
            }
            else if (A == B)
            {
                temp = "平局";
            }
            else {
                temp = "输";
            }

            if (temp == "赢")
            {
                hNum++;
                Console.WriteLine($"笨蛋，{name}输了");
            }
            else if (temp == "输")
            {
                uNum++;
                Console.WriteLine($"恭喜，{name}赢了");
            }
            else {
                Console.WriteLine("平局，再来");
            }
        }
    }
}
